home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / lptalk-1.3 / wrap.c < prev   
C/C++ Source or Header  |  1995-05-03  |  2KB  |  91 lines

  1. /************************************************************************/
  2. /* LP-Talk
  3.     Version 1.0 [ 9/24/90]
  4. 26-Sep-90, shawnm, add partial line print
  5.     Version 1.1 [ 9/27/90]
  6.     Version 1.2 [ 9/28/90]
  7. */
  8. /* TinyTalk word wrapping.                        */
  9. /*                                    */
  10. /*    Version 1.0 [ 1/24/90] : Initial implementation by ABR.        */
  11. /*        1.1 [ 2/ 5/90] : Move input line erasure into here.    */
  12. /*                                    */
  13. /************************************************************************/
  14.  
  15. #include "tl.h"
  16. #include <stdio.h>
  17.  
  18. extern char *rindex();
  19.  
  20. static int current_wrap_column;
  21. static int default_wrap_column;
  22.  
  23. print_with_wrap(s)
  24.   register char *s;
  25. {
  26.   hugestr temp;
  27.   register char *place;
  28.   int loc;
  29.  
  30.   erase_keyboard_input(FALSE);        /* Clear current line. */
  31.  
  32.   if (current_wrap_column == -1)
  33.     current_wrap_column = default_wrap_column;
  34.  
  35.   if ((current_wrap_column == 0) || strlen(s) < current_wrap_column) {
  36.     puts(s);                /* No wrap. */
  37.     log_output(s);
  38.     return;
  39.   }
  40.  
  41.   strcpy(temp, s);
  42.   do {
  43.     temp[current_wrap_column] = '\0';
  44.     place = rindex(temp,' ');
  45.     if (place == NULL) {        /* Can't wrap, give up */
  46.       puts(temp);
  47.       log_output(temp);
  48.       loc = current_wrap_column;
  49.     }
  50.     else {
  51.       *place = '\0';            /* Terminate string */
  52.       puts(temp);            /* and output it. */
  53.       log_output(temp);
  54.       loc = place - temp + 1;
  55.     }
  56.     strcpy(temp, s + loc);        /* Rest of string. */
  57.     strcpy(s, temp);            /* Should strip double spaces? */
  58.   } while (strlen(s) >= current_wrap_column);
  59.  
  60.   if (strlen(s) != 0) {
  61.     puts(s);
  62.     log_output(s);
  63.   }
  64. }
  65.  
  66.  
  67. print_partial_line(s)
  68. char *s;
  69. {
  70.     fputs(s, stdout);
  71.     log_output(s);
  72. }
  73.  
  74.  
  75. enable_wrap(column)            /* Doesn't just set column, because */
  76.   int column;                /* might not have initted keyboard. */
  77. {
  78.   current_wrap_column = ((column == 0) ? -1 : column);
  79. }
  80.  
  81. disable_wrap()
  82. {
  83.   current_wrap_column = 0;
  84. }
  85.  
  86. set_default_wrap(column)
  87.   int column;
  88. {
  89.   default_wrap_column = column;
  90. }
  91.